package nettest;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class IpAddressDemo {
    public static void main(String[] args) {
        try {
            InetAddress[] ias = InetAddress.getAllByName("yinhe-PC");
            for (InetAddress ia:ias) {
                String ip = ia.getHostAddress();
                String name = ia.getHostName();
                System.out.println(ip);
                System.out.println(name);
                System.out.println("-------------------------------------");
            }
            InetAddress ia = InetAddress.getLocalHost();
            String ip = ia.getHostAddress();
            String name = ia.getHostName();
            System.out.println(ip);
            System.out.println(name);

            System.out.println("-------------------------------------");

            InetAddress ib = InetAddress.getByName("www.baidu.com");
            ip = ib.getHostAddress();
            name = ib.getHostName();
            System.out.println(ip);
            System.out.println(name);

            System.out.println("-------------------------------------");

            byte[] addr = {111,13,100,92};
            InetAddress ic = InetAddress.getByAddress(addr);
            ip = ic.getHostAddress();
            name = ic.getHostName();
            System.out.println(ip);
            System.out.println(name);
        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
}
